package com.ocom.webapi.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ocom.common.constant.WebApiServiceUrl;
import com.ocom.common.entity.payconfig.EntityMealPlan;
import com.ocom.common.entity.payconfig.EntityReceiptAddress;
import com.ocom.common.enums.ResultEnum;
import com.ocom.common.request.payconfig.MealPlanListRequest;
import com.ocom.common.request.payconfig.RemoveMealPlanRequest;
import com.ocom.common.request.payconfig.adreceiptinfo.*;
import com.ocom.common.resp.Result;
import com.ocom.common.utils.ResultUtil;
import com.ocom.common.utils.StringUtils;
import com.ocom.security.utils.SecurityUtils;
import com.ocom.webapi.feign.PayConfigClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Description: 取餐点管理
 * @Author: lvwenxiang
 * @Date: 2023/4/24
 **/
@RestController
@PreAuthorize("@pms.hasRole('ROLE_WEB')")
public class AdReceiptPageController {

    @Autowired
    private PayConfigClientService payConfigClientService;


    @PostMapping(WebApiServiceUrl.Url_AdReceiptPageOnShow)
    public Result AdReceiptPageOnShow(@RequestBody GetAdReceiptInfoRequest request) {
        return payConfigClientService.getAdReceiptInfo(request);
    }

    @PostMapping(WebApiServiceUrl.Url_AdReceiptPageAdd)
    public Result AdReceiptPageAdd(@RequestBody EntityReceiptAddress request) {
        String userName = SecurityUtils.getUsername();
        request.setCreateUser(userName);
        request.setUpdateUser(userName);
        return payConfigClientService.addAdReceiptInfo(request);
    }

    @PostMapping(WebApiServiceUrl.Url_AdReceiptPageModify)
    public Result AdReceiptPageModify(@RequestBody UpdateAdReceiptInfoRequest request) {
        request.setUpdateUser(SecurityUtils.getUsername());
        request.setReceiptOrgin(request.getParentReceiptId() + "," + request.getReceiptId());
        return payConfigClientService.updateAdReceiptInfo(request);
    }

    @PostMapping(WebApiServiceUrl.Url_AdReceiptPageDelete)
    public Result AdReceiptPageDelete(@RequestBody DeleteAdReceiptInfoRequest request) {
        return payConfigClientService.deleteAdReceiptInfo(request);
    }

    @PostMapping(WebApiServiceUrl.Url_AdReceiptPageSetOrderCode)
    public Result adReceiptPageSetOrderCode(@RequestBody SetOrderCodeRequest request) {
        return payConfigClientService.setMealOrderCode(request.getComId(), request.getReceiptId());
    }


}
